package com.gimi.cloud.bbp.client.service.userInfo.impl;

import com.gimi.cloud.bbp.client.service.userInfo.WorkInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.exception.MsgException;
import com.gimi.cloud.bbp.dao.dao.User.WorkInfoDao;
import com.gimi.cloud.bbp.dto.userInfo.RdWorkInfoDTO;
import com.gimi.cloud.bbp.entity.userInfo.RdWorkInfoEntity;
@Service
@Transactional
public class WorkInfoServiceImpl implements WorkInfoService {
	
	@Autowired
	private WorkInfoDao workInfoDao;

	@Override
	public void addWorkInfo(RdWorkInfoDTO workInfoDTO) {
		RdWorkInfoEntity record = new RdWorkInfoEntity();
		BeanUtils.copyProperties(workInfoDTO, record);
		int i = workInfoDao.insert(record);
		if (i <= 0) {
			throw new MsgException(ResponseCodeEnum.INVALID,"新增失败!");
		}
	}

	@Override
	public RdWorkInfoDTO getWorkInfoSingle(RdWorkInfoDTO workInfoDTO) {
		RdWorkInfoEntity workInfoEntity = workInfoDao.selectByUserId(workInfoDTO.getUserId()+"");
		RdWorkInfoDTO dto = new RdWorkInfoDTO();
		BeanUtils.copyProperties(workInfoEntity, dto);
		return dto;
	}

	@Override
	public void updateWorkInfo(RdWorkInfoDTO workInfoDTO) {
		RdWorkInfoEntity record = new RdWorkInfoEntity();
		BeanUtils.copyProperties(workInfoDTO, record);
		int i = workInfoDao.updateByPrimaryKeySelective(record);
		if (i <= 0) {
			throw new MsgException(ResponseCodeEnum.INVALID,"更新失败!");
		}
	}

	@Override
	public RdWorkInfoDTO getWorkInfoByUserId(String userId) {
		RdWorkInfoEntity workInfoEntity = workInfoDao.selectByUserId(userId);
		RdWorkInfoDTO dto = new RdWorkInfoDTO();
		BeanUtils.copyProperties(workInfoEntity, dto);
		return dto;
	}

	@Override
	public void deleteWorkInfo(RdWorkInfoDTO workInfoDTO) {
		int i = workInfoDao.deleteByInfoId(workInfoDTO.getInfoId());
		if (i <= 0) {
			throw new MsgException(ResponseCodeEnum.INVALID,"删除失败!");
		}
	}

}
